Skip to content

NOTICKET (feat): Add performance optimization for snowflake external tables#339

Open
Squisher23 wants to merge 4 commits into
ScalefreeCOM:mainfrom
Squisher23:snowflake_external_table_performance_max_days_late
Open

NOTICKET (feat): Add performance optimization for snowflake external tables#339
Squisher23 wants to merge 4 commits into
ScalefreeCOM:mainfrom
Squisher23:snowflake_external_table_performance_max_days_late

Conversation

@Squisher23

Copy link
Copy Markdown

Add performance optimization for snowflake external tables tables by limiting the partitions based on ldts

Description

Snowflake has some weaknesses in external table implementation and only does partition pruning when usings literals as filter on the partition ( see (https://community.snowflake.com/s/article/Pruning-is-not-happening-subquery for details)

The issue #335 already solved our most critical issue with the runtime of satelites, but also links, hubs and tracking-satelites have been getting slower and slower (from seconds to several minutes) with the increasing number of parquet-files in our data lake.

This PR tries to solve the problem by adding a new parameter datavault4dbt.max_days_for_late_arriving_data and filtering all staging tables to the last x days that were configured. Adding this feature speed up our dbt from 30 Minutes to just 5 minutes and should not have other consequences as long as you run dbt more often than the max_days_for_late_arriving_data and you don't have any data sources that deliver data later than the max_days_for_late_arriving_data-Parameter. To recreate the whole vault the parameter needs to be deleted or set to a value high enough

Type of change

Please delete options that are not relevant.

  • [ x] Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

  • Tests you ran

Test Configuration:

  • datavault4dbt-Version: 1.98
  • dbt-Version:core, 1.92
  • dbt-adapter-Version: dbt-snowflake 1.91

Checklist:

  • [ x] I have performed a self-review of my code
  • [ x] I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation or included information that needs updates (e.g. in the Wiki) -> I don't know how to do that

@tkiehn tkiehn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Squisher23 and thanks for reaching out!

Sorry for the late reply, I have reviewed the changes and in general the idea seems like a nice addition to the project.

I pointed out some suggested changes, if you are willing to implement these I would be happy to re-review the PR!

Best Regards
Theo

{# Setting the column name for load date timestamp and record source to the alias coming from the attributes #}
{%- set ldts_alias = var('datavault4dbt.ldts_alias', 'ldts') -%}
{%- set rsrc_alias = var('datavault4dbt.rsrc_alias', 'rsrc') -%}
{%- set max_days_for_late_arriving_data = var('datavault4dbt.max_days_for_late_arriving_data', 'rsrc') -%}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default value is set as 'rsrc', to keep the behaviour backwards compatible, as in no filter is applied, it should default to 0.

Comment on lines +207 to +210
{% if max_days_for_late_arriving_data|int != 0 %}

AND {{ ldts }} >= DATEADD(day, {{ max_days_for_late_arriving_data }}*-1, CURRENT_DATE)
{%- endif -%}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{% if max_days_for_late_arriving_data|int != 0 %}
AND {{ ldts }} >= DATEADD(day, {{ max_days_for_late_arriving_data }}*-1, CURRENT_DATE)
{%- endif -%}
{% if max_days_for_late_arriving_data|int != 0 %}
AND {{ ldts }} >= DATEADD(day, {{ max_days_for_late_arriving_data }}*-1, CURRENT_DATE)
{%- endif -%}

Small readability adjustment

Comment thread dbt_project.yml

#Stage Configuration
datavault4dbt.copy_rsrc_ldts_input_columns: false
datavault4dbt.max_days_for_late_arriving_data:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
datavault4dbt.max_days_for_late_arriving_data:
datavault4dbt.max_days_for_late_arriving_data: 0

Same as above, the default should be set in a way that does not change existing behaviour

@tkiehn tkiehn added the waiting-on-response Waiting on a response from the author or others, except maintainers. label Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on-response Waiting on a response from the author or others, except maintainers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants